<template>
  <HomePanel ref="target" title="人气好物" subTitle="人气推荐 不容错过">
    <div class="home_hot">
      <!-- 动画效果，在ui库里 -->
      <Transition name="fade">
        <ul class="ul_hot" v-if="list.length">
          <li v-for="item in list" :key="item.id">
            <RouterLink to="/">
              <img :src="item.picture" alt="" />
              <p class="name ellipsis">{{ item.title }}</p>
              <p class="des">{{ item.alt }}</p>
            </RouterLink>
          </li>
        </ul>
        <!-- 骨架组件 -->
        <HomeSkeleton v-else></HomeSkeleton>
      </Transition>
    </div>
  </HomePanel>
</template>

<script>
import HomePanel from './home-panel.vue'
import HomeSkeleton from './home-skeleton.vue'
import { getHotGoods } from '@/api/home.js'
import { useLazyData } from '@/utils/hoods.js'
export default {
  components: {
    HomePanel,
    HomeSkeleton
  },
  setup() {
    // 调用封装的数据懒加载函数，获取后台数据
    const { target, list } = useLazyData(getHotGoods)
    return { target, list }
  }
}
</script>
<style lang="less" scoped>
.ul_hot {
  height: 406px;
  display: flex;
  justify-content: space-between;
  li {
    width: 306px;
    height: 100%;
    transition: all 0.5s;
    &:hover {
      transform: translate3d(0, -3px, 0px);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding: 12px 30px 0 30px;
      text-align: center;
    }
    .des {
      font-size: 18px;
      color: #999;
    }
  }
}
</style>
